import turtle as t
import random

points = []
colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue',
          'purple', 'pink', 'black', 'gold']


def gen_list(nums):
    """
    生成小球个数
    :param nums: 数量
    :return:
    """
    dis = 640 // (nums - 1)
    for i in range(nums):
        points.append([350, -320 + i * dis])


def walk():
    """绘制"""
    t.clear()
    # 判读下次是否运行
    is_running = True
    # 绘制小球以及更新坐标
    for i in range(len(points)):
        t.up()
        t.goto(points[i])
        t.down()
        t.dot(20, colors[i])
        points[i][0] -= random.randint(20, 70)
        if points[i][0] < -320:
            is_running = False

    # 绘制终点线
    t.up()
    t.goto(-320, 350)
    t.down()
    t.fillcolor('red')
    t.begin_fill()
    t.goto(-320, -350)
    t.goto(-315, -350)
    t.goto(-315, 350)
    t.goto(-320, 350)
    t.end_fill()
    if is_running:
        t.ontimer(walk, 300)


t.tracer(True)
gen_list(7)
print(points)
walk()

t.done()
